<template>
  <div class="app-container">
    <!-- <doc-alert title="会话日志" url="https://doc.iocoder.cn/system-log/" /> -->
    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户姓名" prop="nickname">
        <el-input v-model="queryParams.nickname" placeholder="请输入用户姓名" clearable style="width: 240px;"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="用户编码" prop="username">
        <el-input v-model="queryParams.username" placeholder="请输入用户编码" clearable style="width: 240px;"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="所属组织" prop="deptName">
        <el-input v-model="queryParams.deptName" placeholder="请输入所属组织" clearable style="width: 240px;"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button v-preventReClick type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button v-preventReClick icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="用户姓名" align="center" prop="nickname" />
      <el-table-column label="用户编码" align="center" prop="username" />
      <el-table-column label="所属组织" align="center" prop="deptName" />
      <el-table-column label="登录IP" align="center" prop="loginIp" />
      <el-table-column label="浏览器" align="center" prop="userAgent" />
      <el-table-column label="操作系统" align="center" prop="os" />
      <el-table-column label="登录时间" align="center" prop="loginTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.loginTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属平台" align="center" prop="openPlatform" />
      <el-table-column label="操作" align="center"  >
      <template v-slot="scope">
        <el-popconfirm
            confirm-button-text='确定'
            cancel-button-text='取消'
            icon="el-icon-info"
            icon-color="red"
            title="确定取消？"
            @confirm="cancelLogin(scope.row)"
          >
            <el-button v-preventReClick type="text" slot="reference">取消登录</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
  </div>
</template>

<script>
import { getAccessTokenPage, deleteAccessToken } from "@/api/infra/manLoginLog"

export default {
  name: "SystemLoginLog",
  data() {
    return {
      // 操作列的弹窗
      visible:false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        username: undefined,
        nickname: undefined,
       // status: undefined,
        //createTime: [],
        deptName:undefined
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询登录日志列表 */
    getList() {
      this.loading = true;
      getAccessTokenPage(this.queryParams).then(response => {
          this.list = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    /** 取消登录操作 */
    cancelLogin(row){
      console.log('我是输出',row)
      const token = row.token;
      this.$modal.confirm('是否确认取消登录用户编码为"' + row.username + '"的登录状态?').then(function() {
        return deleteAccessToken(token);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>

